package com.example.yuntiku.Servlet;

import com.example.yuntiku.Service.QuestionService;
import com.example.yuntiku.dao.impl.ExamanwerDaoImpl;
import com.example.yuntiku.entity.Examanwer;
import com.example.yuntiku.entity.Question;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "AnalyseServlet", value = "/AnalyseServlet")
public class AnalyseServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String shijh = request.getParameter("list");
        String topic = request.getParameter("topic");
        ExamanwerDaoImpl examanwerDao = new ExamanwerDaoImpl();
        QuestionService questionService = new QuestionService();
        List<Examanwer> list = examanwerDao.selectBctim(Integer.parseInt(shijh));
        List<Question> list1 = new ArrayList<>();
        List<String> zqxx = new ArrayList<>();
        List<String> xzhongdan = new ArrayList<>();
        for (Examanwer examanwer : list) {
            Question question = questionService.selectAll(examanwer.getPagerqustionid());
            list1.add(question);
            zqxx.add(examanwer.getRightanswers());
            xzhongdan.add(examanwer.getChooseanswer());
        }
        request.setAttribute("shijh",shijh);
        request.setAttribute("topic",topic);
        request.setAttribute("zqxx",zqxx);
        request.setAttribute("xzhongdan",xzhongdan);
        request.setAttribute("curriculums",list1);
        request.getRequestDispatcher("timcshi.jsp").forward(request,response);

//        ExamanwerService examanwerService = new ExamanwerService();
//        List<Examanwer> list1  = examanwerService.selectBctim(Integer.parseInt(list));
//        for (Examanwer examanwer : list1) {
//            QuestionService questionService = new QuestionService();
//            List<Question> list2 = questionService.selectAll(examanwer.getPagerqustionid());
//            for (Question question : list2) {
//                request.setAttribute("curriculums",list2);
//            }
//        }
//        request.getRequestDispatcher("timcshi.jsp").forward(request,response);
    }
}